function login(email, password) {
	var layIndex = layLoading();
	$.post(ctx + "/admin/sys/user/login.html", {email: email, password: password}, function(data) {
		if(data) {
			layer.close(layIndex);
			
			if(data.success) {
				window.location = ctx + '/admin/index.html';
			} else {
				layAlertFailed(data.msg);
			}
		}
	});
}
function register(email, password) {
	var layIndex = layLoading();
	$.post(ctx + "/admin/sys/user/register.html", {email: email, password: password}, function(data) {
		if(data) {
			layer.close(layIndex);
			
			if(data.success) {
				layAlertSuccess(data.msg);
			} else {
				layAlertFailed(data.msg);
			}
		}
	});
}
function submitAfterValid(method) {
	var email = $("#email").val();
	var password = $("#password").val();
	
	var v = '';
	if(!email) {
		$("#emailTip").html("请输入邮箱地址");
		$("#emailTip").show();
	} else {
		v = validEmail(email);
		if(!v) {
			$("#emailTip").html("请输入合法的邮箱地址");
			$("#emailTip").show();
		} else {
			$("#emailTip").hide();
		}
	}
	if(!password) {
		$("#passwordTip").html("请输入密码");
		$("#passwordTip").show();
	} else {
		$("#passwordTip").hide();
	}
	
	if(email && password) {
		if(v) {
			window[method](email, password);
		}
	} 
}
function toRegister() {
	$("#submit").html("注册");
	$("#submit").attr("onclick", "submitAfterValid('register')");
	$("#lgBtn").html("已有账号？点击登录");
	$("#lgBtn").attr("onclick", "toLogin()");
}
function toLogin() {
	$("#submit").html("登录");
	$("#submit").attr("onclick", "submitAfterValid('login')");
	$("#lgBtn").html("立即注册");
	$("#lgBtn").attr("onclick", "toRegister()");
}

//绑定回车事件,查询
$("body").keypress(function(event){
	var key = event.which;
	if(key == "13"){
		$("#submit").click();
	}
});